﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web.Services;
using System.Web;
using System.Data;
using System.Configuration;

public partial class admin_Cline_buy : System.Web.UI.Page
{
    string p_id;
    string c_id;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["email"] == null)
        {
            Response.Redirect("sessiont.aspx");
        }
        Label2.Text = Session["email"].ToString();


    }
    protected void LinkButton1_Click(object sender, System.EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("../admin.aspx");
    }

    protected void Save_Click(object sender, EventArgs e)
    {
        SqlConnection conn = null;
        

        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        conn.Open();
        Random r1 = new Random();
                int num = r1.Next(0, 99999999); // generate random number
                string number = string.Format("{0:D8}", num);

                Random r2 = new Random();
                int num2 = r2.Next(0, 26); // generate random letter
                char letter = (char)('A' + num2);


                c_id = letter + number; // join both as ID 
                string field = txtfield .Text+ DropDownList10.SelectedValue;


                string p_size = TextBox11.Text + DropDownList7.SelectedValue;

                string balcony = DropDownList14.SelectedValue + TextBox6.Text;
       
            SqlCommand cmd = new SqlCommand("Insert into client_sell values(@c_id,@type,@wants_to,@property,@c_type,@agent_name,@client_fullname,@property_type,@house_no,@city,@street,@ssn,@zip,@country,@email_id,@phone,@block,@room_no,@floor,@safe_room,@ac,@elevator,@price,@p_size,@evacuation_date,@number_of_room,@fields,@electric_boiler,@electric,@kitchen ,@prop_condition,@balconies,@balcony_size,@b_prevelage,@comments,@parking,@c_parking,@furniture,@c_furniture,@toilets,@c_toilets,@shower,@c_shower ,@c_park ,@c_park_info,@direction,@smart_house,@alarm,@bars,@handicap,@teather_room,@gym,@jacuzie,@pool,@adding_by,@date_,@status)", conn);
                
                           
                
                
                cmd.Parameters.AddWithValue("@c_id", c_id);
                cmd.Parameters.AddWithValue("@type", DropDownList5 .SelectedValue );
                cmd.Parameters.AddWithValue("@wants_to", "Sell");
                cmd.Parameters.AddWithValue("@property", DropDownList6.SelectedValue);

                cmd.Parameters.AddWithValue("@c_type", DropDownList20.SelectedValue);
                cmd.Parameters.AddWithValue("@agent_name", DropDownList15.SelectedValue);
                
                cmd.Parameters.AddWithValue("@client_fullname", txtmname .Text );
                cmd.Parameters.AddWithValue("@property_type", txtname1.Text );
                cmd.Parameters.AddWithValue("@house_no", txthno .Text );
                cmd.Parameters.AddWithValue("@city", txtcity.Text );
                cmd.Parameters.AddWithValue("@street", txtstreet.Text );
                cmd.Parameters.AddWithValue("@ssn", txtssn.Text );
                cmd.Parameters.AddWithValue("@zip", txtzip.Text );
                cmd.Parameters.AddWithValue("@country",txtcountry.Text );
                cmd.Parameters.AddWithValue("@email_id", txtemail.Text );
                cmd.Parameters.AddWithValue("@phone", txtphno.Text );
                cmd.Parameters.AddWithValue("@block", TextBox8.Text);
                cmd.Parameters.AddWithValue("@room_no", TextBox3.Text );

                cmd.Parameters.AddWithValue("@floor", TextBox4.Text );
                cmd.Parameters.AddWithValue("@safe_room", TextBox5.Text);

                cmd.Parameters.AddWithValue("@ac", DropDownList16.Text );
                cmd.Parameters.AddWithValue("@elevator", DropDownList16.Text );

                cmd.Parameters.AddWithValue("@price", TextBox9.Text );
                cmd.Parameters.AddWithValue("@p_size",p_size );


                cmd.Parameters.AddWithValue("@evacuation_date", TextBox12.Text);
                cmd.Parameters.AddWithValue("@number_of_room", TextBox14.Text);
              
                
              
              cmd.Parameters.AddWithValue("@fields", field);
              cmd.Parameters.AddWithValue("@electric_boiler", DropDownList9.Text);
              cmd.Parameters.AddWithValue("@electric", TextBox16.Text);
              cmd.Parameters.AddWithValue("@kitchen", DropDownList12.SelectedValue );
              cmd.Parameters.AddWithValue("@prop_condition", DropDownList12.SelectedValue);
              
              
                cmd.Parameters.AddWithValue("@balconies",DropDownList14 .SelectedValue  );
                cmd.Parameters.AddWithValue("@balcony_size", DropDownList17 .SelectedValue );
                
                
                cmd.Parameters.AddWithValue("@b_prevelage", TextBox15.Text );
                cmd.Parameters.AddWithValue("@comments", TextBox13.Text );
                cmd.Parameters.AddWithValue("@parking", ddlcategory .SelectedValue  );
                cmd.Parameters.AddWithValue("@c_parking", txtpark .Text   );
               

                cmd.Parameters.AddWithValue("@furniture", DropDownList18.SelectedValue );
                cmd.Parameters.AddWithValue("@c_furniture", txtfurniture .Text  );
                cmd.Parameters.AddWithValue("@toilets", DropDownList19.SelectedValue);
                cmd.Parameters.AddWithValue("@c_toilets", txttoilets .Text  );
                cmd.Parameters.AddWithValue("@shower", DropDownList16 .SelectedValue   );
                cmd.Parameters.AddWithValue("@c_shower",TextBox16.Text );
               
         cmd.Parameters.AddWithValue("@c_park",DropDownList1.SelectedValue  );
                cmd.Parameters.AddWithValue("@c_park_info",txtcatname .Text  );
                cmd.Parameters.AddWithValue("@direction",CheckBox9.Checked  );
                cmd.Parameters.AddWithValue("@smart_house",CheckBox1 .Checked  );
               cmd.Parameters.AddWithValue("@alarm",CheckBox2 .Checked  );
             cmd.Parameters.AddWithValue("@bars",CheckBox3 .Checked  );
              cmd.Parameters.AddWithValue("@handicap",CheckBox4 .Checked  );
             cmd.Parameters.AddWithValue("@teather_room",CheckBox5 .Checked  );
        cmd.Parameters.AddWithValue("@gym",CheckBox6 .Checked  );
        cmd.Parameters.AddWithValue("@jacuzie",CheckBox7 .Checked  );
       
        cmd.Parameters.AddWithValue("@pool",CheckBox8 .Checked  );
    
                 cmd.Parameters.AddWithValue("@adding_by", Session ["email"]);
                 cmd.Parameters.AddWithValue("@date_", System .DateTime .Now  );
                cmd.Parameters.AddWithValue("@status", "0");
        cmd.ExecuteNonQuery ();
        SqlCommand cmd1 = new SqlCommand("Insert into client_add1 values(@c_id ,@f_name,@type_,@status1)", conn);
        cmd1.Parameters.AddWithValue("@c_id", c_id);
        cmd1.Parameters.AddWithValue("@f_name", txtmname.Text);
        cmd1.Parameters.AddWithValue("@type_", "Sell");

        cmd1.Parameters.AddWithValue("@status1", "0");
        cmd1.ExecuteNonQuery();

        conn.Close();
        Session["c_id"] = c_id;
        Response.Redirect("client_confirmation.aspx?=" + c_id.Trim());

    }
}